/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package GUI;

import Controller.Capacidades.MetodosCapacidades;
import Controller.Pronosticos.MetodosPronosticos;
import Controller.Pronosticos.SuavizacionExponencialSimple;
import Controller.Pronosticos.WinterCompleto;
import Controller.Pronosticos.WinterMultiplicativo;
import java.util.ArrayList;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartFrame;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.data.xy.XYSeries;
import org.jfree.data.xy.XYSeriesCollection;

/**
 *
 * @author camilourd
 */
public class Principal extends javax.swing.JFrame {

    private Nuevo nuevo;
    DefaultTableModel temp;
    int numProd;
    
    private int optionPron = 0;
    // OPciones
    private final int SUAV = 1, WINM = 2, WINC = 3;
    // Graficos
    private JFreeChart chart;
    
    // Métodos de pronósticos
    private SuavizacionExponencialSimple ses;
    private WinterMultiplicativo wmlt;
    private WinterCompleto wcom;
    
    // Metodos Capacidades
    private MetodosCapacidades mcap;
    /**
     * Creates new form Principal
     */
    public Principal() {
        initComponents();
        jTableOperaciones.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jTablePeriodos3 = new javax.swing.JTable();
        jToolBar2 = new javax.swing.JToolBar();
        buttonNuevo = new javax.swing.JButton();
        panelAreaTrabajo = new javax.swing.JPanel();
        jTabbedOperaciones = new javax.swing.JTabbedPane();
        jPanelPronosticos = new javax.swing.JPanel();
        jPanelPronData = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTablePeriodos = new javax.swing.JTable();
        jLabel1 = new javax.swing.JLabel();
        jTextFieldAlpha = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        jTextFieldBeta = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        jTextFieldGamma = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        jComboBoxM = new javax.swing.JComboBox();
        jButtonCalcularPron = new javax.swing.JButton();
        jLabel7 = new javax.swing.JLabel();
        jSpinnerPeriodos = new javax.swing.JSpinner();
        jPanel6 = new javax.swing.JPanel();
        jScrollPane3 = new javax.swing.JScrollPane();
        jTablePronRes = new javax.swing.JTable();
        jTextFieldB = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        jTextFieldA = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        jButtonGrafica = new javax.swing.JButton();
        jLabel8 = new javax.swing.JLabel();
        jTextFieldER = new javax.swing.JTextField();
        jLabel9 = new javax.swing.JLabel();
        jTextFieldDAM = new javax.swing.JTextField();
        jLabel10 = new javax.swing.JLabel();
        jTextFieldERM = new javax.swing.JTextField();
        jLabel11 = new javax.swing.JLabel();
        jTextFieldPEM = new javax.swing.JTextField();
        jLabel12 = new javax.swing.JLabel();
        jTextFieldPEMA = new javax.swing.JTextField();
        jPanel2 = new javax.swing.JPanel();
        jPanelPronData3 = new javax.swing.JPanel();
        jLabel18 = new javax.swing.JLabel();
        jTextIncapacidadLaboral = new javax.swing.JTextField();
        jLabel19 = new javax.swing.JLabel();
        jTextFieldActividadesLudicas = new javax.swing.JTextField();
        jLabel20 = new javax.swing.JLabel();
        jTextFieldParadasPlanta = new javax.swing.JTextField();
        jLabel21 = new javax.swing.JLabel();
        jButtonCalcularCapacidades = new javax.swing.JButton();
        jLabel22 = new javax.swing.JLabel();
        jSpinnerProductos = new javax.swing.JSpinner();
        jSpinnerNumTurnos = new javax.swing.JSpinner();
        jLabel23 = new javax.swing.JLabel();
        jSpinnerHoras = new javax.swing.JSpinner();
        jSpinnerMinutos = new javax.swing.JSpinner();
        jLabel24 = new javax.swing.JLabel();
        jLabel25 = new javax.swing.JLabel();
        jScrollPane5 = new javax.swing.JScrollPane();
        jTableOperaciones = new javax.swing.JTable();
        jLabel28 = new javax.swing.JLabel();
        jComboBoxHorizontePlaneacion = new javax.swing.JComboBox();
        jPanel7 = new javax.swing.JPanel();
        jScrollPane6 = new javax.swing.JScrollPane();
        jTableOpeRes = new javax.swing.JTable();
        jTextFieldCds = new javax.swing.JTextField();
        jLabel13 = new javax.swing.JLabel();
        jTextFieldCt = new javax.swing.JTextField();
        jLabel14 = new javax.swing.JLabel();
        jLabel15 = new javax.swing.JLabel();
        jTextFieldCr = new javax.swing.JTextField();
        jLabel16 = new javax.swing.JLabel();
        jTextFieldCi = new javax.swing.JTextField();
        jLabel17 = new javax.swing.JLabel();
        jTextFieldFus = new javax.swing.JTextField();
        jLabel27 = new javax.swing.JLabel();
        jTextFieldFuci = new javax.swing.JTextField();
        jPanel3 = new javax.swing.JPanel();
        jPanelPronData1 = new javax.swing.JPanel();
        jScrollPane4 = new javax.swing.JScrollPane();
        jTablePeriodosCon = new javax.swing.JTable();
        jButtonCalcularPron1 = new javax.swing.JButton();
        barraMenus = new javax.swing.JMenuBar();
        menuArchivo = new javax.swing.JMenu();
        menuItemNuevo = new javax.swing.JMenu();
        jMenuPronostico = new javax.swing.JMenu();
        jMenuItemSuavizacion = new javax.swing.JMenuItem();
        jMenuItemWinterM = new javax.swing.JMenuItem();
        jMenuItemWinterC = new javax.swing.JMenuItem();
        jMenuItemCpacidades = new javax.swing.JMenuItem();
        jSeparator1 = new javax.swing.JPopupMenu.Separator();
        menuItemSalir = new javax.swing.JMenuItem();
        jMenu2 = new javax.swing.JMenu();

        jTablePeriodos3.setAutoCreateColumnsFromModel(false);
        jTablePeriodos3.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {},
                {},
                {},
                {}
            },
            new String [] {

            }
        ));
        jTablePeriodos3.setFocusTraversalPolicyProvider(true);
        jTablePeriodos3.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        jTablePeriodos3.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jTableOperacionesKeyPressed(evt);
            }
        });

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Aplicación producción");
        setMinimumSize(new java.awt.Dimension(800, 700));

        jToolBar2.setRollover(true);

        buttonNuevo.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Images/buttons/buttonNuevo.png"))); // NOI18N
        buttonNuevo.setToolTipText("Hola");
        buttonNuevo.setFocusable(false);
        buttonNuevo.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        buttonNuevo.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        buttonNuevo.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                buttonNuevoMouseClicked(evt);
            }
        });
        jToolBar2.add(buttonNuevo);

        panelAreaTrabajo.setName("panelAreaTrabajo"); // NOI18N

        jPanelPronData.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Datos", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Arial", 1, 12))); // NOI18N

        jTablePeriodos.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {},
                {},
                {},
                {}
            },
            new String [] {

            }
        ));
        jTablePeriodos.setFocusTraversalPolicyProvider(true);
        jTablePeriodos.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        jTablePeriodos.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jTablePeriodosKeyPressed(evt);
            }
        });
        jScrollPane1.setViewportView(jTablePeriodos);

        jLabel1.setFont(new java.awt.Font("Arial", 1, 15)); // NOI18N
        jLabel1.setText("Alpha:");

        jTextFieldAlpha.setToolTipText("");

        jLabel2.setFont(new java.awt.Font("Arial", 1, 15)); // NOI18N
        jLabel2.setText("Beta:");

        jTextFieldBeta.setToolTipText("");

        jLabel3.setFont(new java.awt.Font("Arial", 1, 15)); // NOI18N
        jLabel3.setText("Gamma:");

        jTextFieldGamma.setToolTipText("");

        jLabel4.setFont(new java.awt.Font("Arial", 1, 15)); // NOI18N
        jLabel4.setText("Unidad de tiempo(m):");

        jComboBoxM.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Días", "Semanas", "Meses", "trimestres" }));

        jButtonCalcularPron.setText("Calcular");
        jButtonCalcularPron.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonCalcularPronActionPerformed(evt);
            }
        });

        jLabel7.setFont(new java.awt.Font("Arial", 1, 15)); // NOI18N
        jLabel7.setText("Número de periodos a calcular:");

        jSpinnerPeriodos.setModel(new javax.swing.SpinnerNumberModel(1, 1, 30, 1));
        jSpinnerPeriodos.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        jSpinnerPeriodos.setInheritsPopupMenu(true);

        javax.swing.GroupLayout jPanelPronDataLayout = new javax.swing.GroupLayout(jPanelPronData);
        jPanelPronData.setLayout(jPanelPronDataLayout);
        jPanelPronDataLayout.setHorizontalGroup(
            jPanelPronDataLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelPronDataLayout.createSequentialGroup()
                .addGap(27, 27, 27)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 983, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(26, Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanelPronDataLayout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jPanelPronDataLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanelPronDataLayout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addGap(4, 4, 4)
                        .addComponent(jTextFieldAlpha, javax.swing.GroupLayout.PREFERRED_SIZE, 51, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jLabel2)
                        .addGap(4, 4, 4)
                        .addComponent(jTextFieldBeta, javax.swing.GroupLayout.PREFERRED_SIZE, 51, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jLabel3)
                        .addGap(4, 4, 4)
                        .addComponent(jTextFieldGamma, javax.swing.GroupLayout.PREFERRED_SIZE, 51, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jLabel4)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jComboBoxM, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanelPronDataLayout.createSequentialGroup()
                        .addGap(27, 27, 27)
                        .addComponent(jLabel7)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jSpinnerPeriodos, javax.swing.GroupLayout.PREFERRED_SIZE, 61, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jButtonCalcularPron, javax.swing.GroupLayout.PREFERRED_SIZE, 250, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(202, 202, 202))
        );
        jPanelPronDataLayout.setVerticalGroup(
            jPanelPronDataLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelPronDataLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 116, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 11, Short.MAX_VALUE)
                .addGroup(jPanelPronDataLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanelPronDataLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel3)
                        .addComponent(jTextFieldGamma, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel4)
                        .addComponent(jComboBoxM, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanelPronDataLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel2)
                        .addComponent(jTextFieldBeta, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanelPronDataLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel1)
                        .addComponent(jTextFieldAlpha, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(7, 7, 7)
                .addGroup(jPanelPronDataLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel7)
                    .addComponent(jButtonCalcularPron)
                    .addComponent(jSpinnerPeriodos))
                .addContainerGap())
        );

        jPanel6.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Resultados", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Arial", 1, 12))); // NOI18N

        jTablePronRes.setAutoCreateRowSorter(true);
        jTablePronRes.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {},
                {},
                {},
                {}
            },
            new String [] {

            }
        ));
        jTablePronRes.setEnabled(false);
        jTablePronRes.setFocusTraversalPolicyProvider(true);
        jScrollPane3.setViewportView(jTablePronRes);

        jTextFieldB.setToolTipText("");
        jTextFieldB.setEnabled(false);

        jLabel6.setFont(new java.awt.Font("Arial", 1, 15)); // NOI18N
        jLabel6.setText("b:");

        jTextFieldA.setToolTipText("");
        jTextFieldA.setEnabled(false);

        jLabel5.setFont(new java.awt.Font("Arial", 1, 15)); // NOI18N
        jLabel5.setText("a:");

        jButtonGrafica.setText("Ver Gráfica");
        jButtonGrafica.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonGraficaActionPerformed(evt);
            }
        });

        jLabel8.setFont(new java.awt.Font("Arial", 1, 15)); // NOI18N
        jLabel8.setText("Error residual:");

        jTextFieldER.setToolTipText("");
        jTextFieldER.setEnabled(false);

        jLabel9.setFont(new java.awt.Font("Arial", 1, 15)); // NOI18N
        jLabel9.setText("Desviación media absoluta:");

        jTextFieldDAM.setToolTipText("");
        jTextFieldDAM.setEnabled(false);

        jLabel10.setFont(new java.awt.Font("Arial", 1, 15)); // NOI18N
        jLabel10.setText("Error medio cuadrático:");

        jTextFieldERM.setToolTipText("");
        jTextFieldERM.setEnabled(false);

        jLabel11.setFont(new java.awt.Font("Arial", 1, 15)); // NOI18N
        jLabel11.setText("Porcentaje de error medio:");

        jTextFieldPEM.setToolTipText("");
        jTextFieldPEM.setEnabled(false);

        jLabel12.setFont(new java.awt.Font("Arial", 1, 15)); // NOI18N
        jLabel12.setText("Procentaje de error medio absoluto:");

        jTextFieldPEMA.setToolTipText("");
        jTextFieldPEMA.setEnabled(false);

        javax.swing.GroupLayout jPanel6Layout = new javax.swing.GroupLayout(jPanel6);
        jPanel6.setLayout(jPanel6Layout);
        jPanel6Layout.setHorizontalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel6Layout.createSequentialGroup()
                .addGap(0, 0, Short.MAX_VALUE)
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel5)
                    .addComponent(jLabel8)
                    .addComponent(jLabel10))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel6Layout.createSequentialGroup()
                        .addComponent(jLabel12)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jTextFieldPEMA, javax.swing.GroupLayout.PREFERRED_SIZE, 180, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel6Layout.createSequentialGroup()
                        .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jTextFieldA)
                            .addComponent(jTextFieldER)
                            .addComponent(jTextFieldERM, javax.swing.GroupLayout.PREFERRED_SIZE, 180, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(83, 83, 83)
                        .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(jPanel6Layout.createSequentialGroup()
                                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel6Layout.createSequentialGroup()
                                        .addComponent(jLabel11)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED))
                                    .addGroup(jPanel6Layout.createSequentialGroup()
                                        .addComponent(jLabel9)
                                        .addGap(9, 9, 9)))
                                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(jTextFieldDAM)
                                    .addComponent(jTextFieldPEM, javax.swing.GroupLayout.PREFERRED_SIZE, 180, javax.swing.GroupLayout.PREFERRED_SIZE)))
                            .addGroup(jPanel6Layout.createSequentialGroup()
                                .addComponent(jLabel6)
                                .addGap(9, 9, 9)
                                .addComponent(jTextFieldB, javax.swing.GroupLayout.PREFERRED_SIZE, 180, javax.swing.GroupLayout.PREFERRED_SIZE)))))
                .addGap(97, 97, 97))
            .addGroup(jPanel6Layout.createSequentialGroup()
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel6Layout.createSequentialGroup()
                        .addGap(27, 27, 27)
                        .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 981, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel6Layout.createSequentialGroup()
                        .addGap(419, 419, 419)
                        .addComponent(jButtonGrafica, javax.swing.GroupLayout.PREFERRED_SIZE, 180, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel6Layout.setVerticalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel6Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 116, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jTextFieldA, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel6)
                    .addComponent(jTextFieldB, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel5))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jTextFieldER, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel9)
                    .addComponent(jTextFieldDAM, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel8))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jTextFieldERM, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel11)
                    .addComponent(jTextFieldPEM, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel10))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel12)
                    .addComponent(jTextFieldPEMA, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jButtonGrafica)
                .addContainerGap(65, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout jPanelPronosticosLayout = new javax.swing.GroupLayout(jPanelPronosticos);
        jPanelPronosticos.setLayout(jPanelPronosticosLayout);
        jPanelPronosticosLayout.setHorizontalGroup(
            jPanelPronosticosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanelPronData, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(jPanel6, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        jPanelPronosticosLayout.setVerticalGroup(
            jPanelPronosticosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelPronosticosLayout.createSequentialGroup()
                .addComponent(jPanelPronData, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel6, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jTabbedOperaciones.addTab("Pronósticos", jPanelPronosticos);

        jPanelPronData3.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Datos", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Arial", 1, 12))); // NOI18N

        jLabel18.setFont(new java.awt.Font("Arial", 1, 15)); // NOI18N
        jLabel18.setText("Número de turnos de los procesos:");

        jTextIncapacidadLaboral.setToolTipText("");
        jTextIncapacidadLaboral.setEnabled(false);

        jLabel19.setFont(new java.awt.Font("Arial", 1, 15)); // NOI18N
        jLabel19.setText("horas");

        jTextFieldActividadesLudicas.setToolTipText("");
        jTextFieldActividadesLudicas.setEnabled(false);

        jLabel20.setFont(new java.awt.Font("Arial", 1, 15)); // NOI18N
        jLabel20.setText("minutos");

        jTextFieldParadasPlanta.setToolTipText("");
        jTextFieldParadasPlanta.setEnabled(false);

        jLabel21.setFont(new java.awt.Font("Arial", 1, 15)); // NOI18N
        jLabel21.setText("Horas de incapacidad laboral:");

        jButtonCalcularCapacidades.setText("Calcular");
        jButtonCalcularCapacidades.setEnabled(false);
        jButtonCalcularCapacidades.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonCalcularCapacidadesActionPerformed(evt);
            }
        });

        jLabel22.setFont(new java.awt.Font("Arial", 1, 15)); // NOI18N
        jLabel22.setText("Número de productos:");

        jSpinnerProductos.setModel(new javax.swing.SpinnerNumberModel(1, 1, 5, 1));
        jSpinnerProductos.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        jSpinnerProductos.setEnabled(false);
        jSpinnerProductos.setInheritsPopupMenu(true);
        jSpinnerProductos.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                jSpinnerProductosStateChanged(evt);
            }
        });

        jSpinnerNumTurnos.setModel(new javax.swing.SpinnerNumberModel(1, 1, 3, 1));
        jSpinnerNumTurnos.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        jSpinnerNumTurnos.setEnabled(false);
        jSpinnerNumTurnos.setInheritsPopupMenu(true);

        jLabel23.setFont(new java.awt.Font("Arial", 1, 15)); // NOI18N
        jLabel23.setText("Duración de los turnos de los procesos:");

        jSpinnerHoras.setModel(new javax.swing.SpinnerNumberModel(0, 0, 23, 1));
        jSpinnerHoras.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        jSpinnerHoras.setEnabled(false);
        jSpinnerHoras.setInheritsPopupMenu(true);

        jSpinnerMinutos.setModel(new javax.swing.SpinnerNumberModel(0, 0, 59, 1));
        jSpinnerMinutos.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        jSpinnerMinutos.setEnabled(false);
        jSpinnerMinutos.setInheritsPopupMenu(true);

        jLabel24.setFont(new java.awt.Font("Arial", 1, 15)); // NOI18N
        jLabel24.setText("Horas de actividades lúdicas o culturales:");

        jLabel25.setFont(new java.awt.Font("Arial", 1, 15)); // NOI18N
        jLabel25.setText("Paradas de planta no programadas:");

        jTableOperaciones.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {},
                {},
                {},
                {}
            },
            new String [] {

            }
        ));
        jTableOperaciones.setFocusTraversalPolicyProvider(true);
        jTableOperaciones.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        jTableOperaciones.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jTableOperacionesKeyPressed(evt);
            }
        });
        jScrollPane5.setViewportView(jTableOperaciones);

        jLabel28.setFont(new java.awt.Font("Arial", 1, 15)); // NOI18N
        jLabel28.setText("Horizonte de planeacion:");

        jComboBoxHorizontePlaneacion.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "mes", "bimestre", "trimestre", "semestre", "año", "dos años" }));
        jComboBoxHorizontePlaneacion.setEnabled(false);

        javax.swing.GroupLayout jPanelPronData3Layout = new javax.swing.GroupLayout(jPanelPronData3);
        jPanelPronData3.setLayout(jPanelPronData3Layout);
        jPanelPronData3Layout.setHorizontalGroup(
            jPanelPronData3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelPronData3Layout.createSequentialGroup()
                .addGap(27, 27, 27)
                .addGroup(jPanelPronData3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane5, javax.swing.GroupLayout.PREFERRED_SIZE, 989, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jPanelPronData3Layout.createSequentialGroup()
                        .addGap(12, 12, 12)
                        .addGroup(jPanelPronData3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanelPronData3Layout.createSequentialGroup()
                                .addComponent(jLabel22)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(jPanelPronData3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(jPanelPronData3Layout.createSequentialGroup()
                                        .addGap(12, 12, 12)
                                        .addComponent(jLabel23)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(jSpinnerHoras, javax.swing.GroupLayout.PREFERRED_SIZE, 61, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(4, 4, 4)
                                        .addComponent(jLabel19)
                                        .addGap(2, 2, 2)
                                        .addComponent(jSpinnerMinutos, javax.swing.GroupLayout.PREFERRED_SIZE, 61, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(3, 3, 3)
                                        .addComponent(jLabel20))
                                    .addGroup(jPanelPronData3Layout.createSequentialGroup()
                                        .addComponent(jSpinnerProductos, javax.swing.GroupLayout.PREFERRED_SIZE, 61, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(18, 18, 18)
                                        .addComponent(jLabel18)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(jSpinnerNumTurnos, javax.swing.GroupLayout.PREFERRED_SIZE, 61, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(18, 18, 18)
                                        .addComponent(jLabel28)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(jComboBoxHorizontePlaneacion, javax.swing.GroupLayout.PREFERRED_SIZE, 103, javax.swing.GroupLayout.PREFERRED_SIZE))))
                            .addGroup(jPanelPronData3Layout.createSequentialGroup()
                                .addGroup(jPanelPronData3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addComponent(jButtonCalcularCapacidades, javax.swing.GroupLayout.PREFERRED_SIZE, 250, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addGroup(jPanelPronData3Layout.createSequentialGroup()
                                        .addComponent(jLabel21)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(jTextIncapacidadLaboral, javax.swing.GroupLayout.PREFERRED_SIZE, 51, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(jLabel24)))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jTextFieldActividadesLudicas, javax.swing.GroupLayout.PREFERRED_SIZE, 51, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jLabel25)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jTextFieldParadasPlanta, javax.swing.GroupLayout.PREFERRED_SIZE, 51, javax.swing.GroupLayout.PREFERRED_SIZE)))))
                .addContainerGap(20, Short.MAX_VALUE))
        );
        jPanelPronData3Layout.setVerticalGroup(
            jPanelPronData3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelPronData3Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane5, javax.swing.GroupLayout.PREFERRED_SIZE, 128, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(4, 4, 4)
                .addGroup(jPanelPronData3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel22)
                    .addComponent(jSpinnerProductos)
                    .addComponent(jLabel18)
                    .addComponent(jSpinnerNumTurnos)
                    .addComponent(jLabel28)
                    .addComponent(jComboBoxHorizontePlaneacion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanelPronData3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel23)
                    .addComponent(jSpinnerHoras)
                    .addComponent(jSpinnerMinutos)
                    .addComponent(jLabel20)
                    .addComponent(jLabel19))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanelPronData3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel21)
                    .addComponent(jTextIncapacidadLaboral, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel24)
                    .addComponent(jTextFieldActividadesLudicas, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jTextFieldParadasPlanta, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel25))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButtonCalcularCapacidades))
        );

        jPanel7.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Resultados", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Arial", 1, 12))); // NOI18N

        jTableOpeRes.setAutoCreateRowSorter(true);
        jTableOpeRes.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {},
                {},
                {},
                {}
            },
            new String [] {

            }
        ));
        jTableOpeRes.setEnabled(false);
        jTableOpeRes.setFocusTraversalPolicyProvider(true);
        jScrollPane6.setViewportView(jTableOpeRes);

        jTextFieldCds.setToolTipText("");
        jTextFieldCds.setEnabled(false);

        jLabel13.setFont(new java.awt.Font("Arial", 1, 15)); // NOI18N
        jLabel13.setText("Capacidad disponible del sistema:");

        jTextFieldCt.setToolTipText("");
        jTextFieldCt.setEnabled(false);

        jLabel14.setFont(new java.awt.Font("Arial", 1, 15)); // NOI18N
        jLabel14.setText("Capacidad teórica:");

        jLabel15.setFont(new java.awt.Font("Arial", 1, 15)); // NOI18N
        jLabel15.setText("Capacidad requerida:");

        jTextFieldCr.setToolTipText("");
        jTextFieldCr.setEnabled(false);

        jLabel16.setFont(new java.awt.Font("Arial", 1, 15)); // NOI18N
        jLabel16.setText("Capacidad instalada:");

        jTextFieldCi.setToolTipText("");
        jTextFieldCi.setEnabled(false);

        jLabel17.setFont(new java.awt.Font("Arial", 1, 15)); // NOI18N
        jLabel17.setText("Factor de utilización del sistema:");

        jTextFieldFus.setToolTipText("");
        jTextFieldFus.setEnabled(false);

        jLabel27.setFont(new java.awt.Font("Arial", 1, 15)); // NOI18N
        jLabel27.setText("Factor de utilización de la capacidad instalada:");

        jTextFieldFuci.setToolTipText("");
        jTextFieldFuci.setEnabled(false);

        javax.swing.GroupLayout jPanel7Layout = new javax.swing.GroupLayout(jPanel7);
        jPanel7.setLayout(jPanel7Layout);
        jPanel7Layout.setHorizontalGroup(
            jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel7Layout.createSequentialGroup()
                .addGap(27, 27, 27)
                .addComponent(jScrollPane6, javax.swing.GroupLayout.PREFERRED_SIZE, 982, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel7Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel7Layout.createSequentialGroup()
                        .addComponent(jLabel16)
                        .addGap(18, 18, 18)
                        .addComponent(jTextFieldCi, javax.swing.GroupLayout.PREFERRED_SIZE, 180, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel7Layout.createSequentialGroup()
                        .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel14)
                            .addComponent(jLabel15))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jTextFieldCt)
                            .addComponent(jTextFieldCr, javax.swing.GroupLayout.PREFERRED_SIZE, 180, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addGap(40, 40, 40)
                .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jPanel7Layout.createSequentialGroup()
                        .addComponent(jLabel27)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jTextFieldFuci, javax.swing.GroupLayout.PREFERRED_SIZE, 180, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel7Layout.createSequentialGroup()
                        .addComponent(jLabel13)
                        .addGap(9, 9, 9)
                        .addComponent(jTextFieldCds, javax.swing.GroupLayout.PREFERRED_SIZE, 180, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel7Layout.createSequentialGroup()
                        .addComponent(jLabel17)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jTextFieldFus, javax.swing.GroupLayout.PREFERRED_SIZE, 180, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(63, 63, 63))
        );
        jPanel7Layout.setVerticalGroup(
            jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel7Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane6, javax.swing.GroupLayout.PREFERRED_SIZE, 116, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jTextFieldCt, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel13)
                    .addComponent(jTextFieldCds, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel14))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jTextFieldCr, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel15)
                    .addComponent(jTextFieldFus, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel17))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel16)
                    .addComponent(jTextFieldCi, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel27)
                        .addComponent(jTextFieldFuci, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanelPronData3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(jPanel7, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addComponent(jPanelPronData3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel7, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        jTabbedOperaciones.addTab("Capacidades", null, jPanel2, "");

        jPanelPronData1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Datos", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Arial", 1, 12))); // NOI18N

        jTablePeriodosCon.setAutoCreateRowSorter(true);
        jTablePeriodosCon.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null}
            },
            new String [] {
                "Periodo", "Demanda", "Días Hábiles", "Stock Seguridad"
            }
        ));
        jTablePeriodosCon.setFocusTraversalPolicyProvider(true);
        jTablePeriodosCon.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jTablePeriodosConKeyPressed(evt);
            }
        });
        jScrollPane4.setViewportView(jTablePeriodosCon);

        jButtonCalcularPron1.setText("Calcular");
        jButtonCalcularPron1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonCalcularPron1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanelPronData1Layout = new javax.swing.GroupLayout(jPanelPronData1);
        jPanelPronData1.setLayout(jPanelPronData1Layout);
        jPanelPronData1Layout.setHorizontalGroup(
            jPanelPronData1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelPronData1Layout.createSequentialGroup()
                .addGroup(jPanelPronData1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanelPronData1Layout.createSequentialGroup()
                        .addGap(342, 342, 342)
                        .addComponent(jButtonCalcularPron1, javax.swing.GroupLayout.PREFERRED_SIZE, 250, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanelPronData1Layout.createSequentialGroup()
                        .addGap(27, 27, 27)
                        .addComponent(jScrollPane4, javax.swing.GroupLayout.PREFERRED_SIZE, 717, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(292, Short.MAX_VALUE))
        );
        jPanelPronData1Layout.setVerticalGroup(
            jPanelPronData1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelPronData1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane4, javax.swing.GroupLayout.PREFERRED_SIZE, 116, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 46, Short.MAX_VALUE)
                .addComponent(jButtonCalcularPron1)
                .addContainerGap())
        );

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanelPronData1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addComponent(jPanelPronData1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 399, Short.MAX_VALUE))
        );

        jTabbedOperaciones.addTab("Contratación y Despido", jPanel3);

        javax.swing.GroupLayout panelAreaTrabajoLayout = new javax.swing.GroupLayout(panelAreaTrabajo);
        panelAreaTrabajo.setLayout(panelAreaTrabajoLayout);
        panelAreaTrabajoLayout.setHorizontalGroup(
            panelAreaTrabajoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jTabbedOperaciones)
        );
        panelAreaTrabajoLayout.setVerticalGroup(
            panelAreaTrabajoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jTabbedOperaciones)
        );

        barraMenus.setName(""); // NOI18N

        menuArchivo.setText("Archivo");

        menuItemNuevo.setText("Nuevo");

        jMenuPronostico.setText("Pronóstico");

        jMenuItemSuavizacion.setText("Suavización exponencial simple");
        jMenuItemSuavizacion.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItemSuavizacionActionPerformed(evt);
            }
        });
        jMenuPronostico.add(jMenuItemSuavizacion);

        jMenuItemWinterM.setText("Winter Multiplicativo");
        jMenuItemWinterM.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItemWinterMActionPerformed(evt);
            }
        });
        jMenuPronostico.add(jMenuItemWinterM);

        jMenuItemWinterC.setText("Winter Completo");
        jMenuItemWinterC.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItemWinterCActionPerformed(evt);
            }
        });
        jMenuPronostico.add(jMenuItemWinterC);

        menuItemNuevo.add(jMenuPronostico);

        jMenuItemCpacidades.setText("Capacidades");
        jMenuItemCpacidades.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItemCpacidadesActionPerformed(evt);
            }
        });
        menuItemNuevo.add(jMenuItemCpacidades);

        menuArchivo.add(menuItemNuevo);
        menuArchivo.add(jSeparator1);

        menuItemSalir.setText("Salir");
        menuItemSalir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menuItemSalirActionPerformed(evt);
            }
        });
        menuArchivo.add(menuItemSalir);

        barraMenus.add(menuArchivo);

        jMenu2.setText("Edit");
        barraMenus.add(jMenu2);

        setJMenuBar(barraMenus);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jToolBar2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(panelAreaTrabajo, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jToolBar2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(panelAreaTrabajo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButtonCalcularPronActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonCalcularPronActionPerformed
        // TODO add your handling code here:
        if(optionPron == SUAV) {
            calcularSuavizacionExponencialSimple();
        } else if(optionPron == WINM) {
            calcularWinterMultiplicativo();
        } else if(optionPron == WINC) {
            calcularWinterCompleto();
        }
    }//GEN-LAST:event_jButtonCalcularPronActionPerformed

    private void jButtonGraficaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonGraficaActionPerformed
        if(optionPron != 0) {
            String title = "Gráfica Suavización Exponencial Simple";
            // Create a simple XY chart
            XYSeries seriesYt = new XYSeries("Demanda");
            XYSeries seriesYp = new XYSeries("Pronostico");
            XYSeries seriesTend = new XYSeries("Línea de tendencia");
            if(optionPron == SUAV) ses.obtenerDatosGrafico(seriesYt, seriesYp, seriesTend);
            if(optionPron == WINM) wmlt.obtenerDatosGrafico(seriesYt, seriesYp, seriesTend);
            if(optionPron == WINC) wcom.obtenerDatosGrafico(seriesYt, seriesYp, seriesTend);
            // Add the series to your data set
            XYSeriesCollection dataset = new XYSeriesCollection();
            dataset.addSeries(seriesYt);
            dataset.addSeries(seriesYp);
            dataset.addSeries(seriesTend);
            
            chart = ChartFactory.createXYLineChart(
                    "Resultados Suavización Exponenecial Simple",
                    "Periodos",
                    "Demanda",
                    dataset, PlotOrientation.VERTICAL,
                    true,
                    true,
                    false);
            
            ChartFrame frame = new ChartFrame(title, chart);
            frame.pack();
            frame.setVisible(true);
        }
    }//GEN-LAST:event_jButtonGraficaActionPerformed

    private void menuItemSalirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuItemSalirActionPerformed
        // TODO add your handling code here:
        System.exit(0);
    }//GEN-LAST:event_menuItemSalirActionPerformed

    private void buttonNuevoMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_buttonNuevoMouseClicked
        nuevo = new Nuevo();
        nuevo.setVisible(true);
    }//GEN-LAST:event_buttonNuevoMouseClicked

    private void jMenuItemWinterMActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItemWinterMActionPerformed
        // TODO add your handling code here:
        initPronosticos(WINM);
    }//GEN-LAST:event_jMenuItemWinterMActionPerformed

    private void jMenuItemSuavizacionActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItemSuavizacionActionPerformed
        // TODO add your handling code here:
        initPronosticos(SUAV);
    }//GEN-LAST:event_jMenuItemSuavizacionActionPerformed

    private void jTablePeriodosKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTablePeriodosKeyPressed
        // TODO add your handling code here:
        if(evt.getKeyCode() == 9) { // Agregar fila
            temp = (DefaultTableModel) jTablePeriodos.getModel();
            
            if(temp.getRowCount() - 1 == jTablePeriodos.getSelectedRow() &&
               temp.getColumnCount() - 1 == jTablePeriodos.getSelectedColumn()) {
                if(optionPron == SUAV || optionPron == WINC){
                    Object nuevaFila[]= {"", "", ""};
                    temp.addRow(nuevaFila);
                } else if(optionPron == WINM) {
                    Object nuevaFila[]= {"", "", "", "", ""};
                    temp.addRow(nuevaFila);
                }
            }
        } else if(evt.getKeyCode() == 127) { // Borrar Fila
            temp = (DefaultTableModel) jTablePeriodos.getModel();
            temp.removeRow(jTablePeriodos.getSelectedRow());
            
            if(temp.getRowCount() == 0) {
                if(optionPron == SUAV || optionPron == WINC){
                    Object nuevaFila[]= {"", "", ""};
                    temp.addRow(nuevaFila);
                } else if(optionPron == WINM) {
                    Object nuevaFila[]= {"", "", "", "", ""};
                    temp.addRow(nuevaFila);
                }
            }
        }
    }//GEN-LAST:event_jTablePeriodosKeyPressed

    private void jMenuItemWinterCActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItemWinterCActionPerformed
        initPronosticos(WINC);
    }//GEN-LAST:event_jMenuItemWinterCActionPerformed

    private void jTablePeriodosConKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTablePeriodosConKeyPressed
        if(evt.getKeyCode() == 9) { // Agregar fila
            temp = (DefaultTableModel) jTablePeriodosCon.getModel();
            
            if(temp.getRowCount() - 1 == jTablePeriodosCon.getSelectedRow() &&
               temp.getColumnCount() - 1 == jTablePeriodosCon.getSelectedColumn()) {
                Object nuevaFila[]= {"", "", "", ""};
                temp.addRow(nuevaFila);
            }
        } else if(evt.getKeyCode() == 127) { // Borrar Fila
            temp = (DefaultTableModel) jTablePeriodosCon.getModel();
            temp.removeRow(jTablePeriodosCon.getSelectedRow());
            
            if(temp.getRowCount() == 0) {
                Object nuevaFila[]= {"", "", "", ""};
                temp.addRow(nuevaFila);
            }
        }
    }//GEN-LAST:event_jTablePeriodosConKeyPressed

    private void jButtonCalcularPron1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonCalcularPron1ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jButtonCalcularPron1ActionPerformed

    private void jButtonCalcularCapacidadesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonCalcularCapacidadesActionPerformed
        calcularCapacidades();
    }//GEN-LAST:event_jButtonCalcularCapacidadesActionPerformed

    private void jSpinnerProductosStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_jSpinnerProductosStateChanged
        initTableOperacion();
    }//GEN-LAST:event_jSpinnerProductosStateChanged

    private void jTableOperacionesKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTableOperacionesKeyPressed
        if(evt.getKeyCode() == 9) { // Agregar fila
            temp = (DefaultTableModel) jTableOperaciones.getModel();

            if(temp.getRowCount() - 5 == jTableOperaciones.getSelectedRow() &&
                temp.getColumnCount() - 1 == jTableOperaciones.getSelectedColumn()) {
                Object nuevaFila[]= new Object[9 + numProd];
                for(int i = 0;i < numProd + 9; ++i) nuevaFila[i] = "";
                temp.insertRow(temp.getRowCount() - 4, nuevaFila);
                escribirProcesos();
            }
        } else if(evt.getKeyCode() == 127 && temp.getRowCount() - 4 > jTableOperaciones.getSelectedRow()) { // Borrar Fila
            temp = (DefaultTableModel) jTableOperaciones.getModel();
            temp.removeRow(jTableOperaciones.getSelectedRow());

            if(temp.getRowCount() == 4) {
                Object nuevaFila[]= new Object[9 + numProd];
                for(int i = 0;i < numProd + 9; ++i) nuevaFila[i] = "";
                temp.insertRow(0, nuevaFila);
            }
            escribirProcesos();
        }
    }//GEN-LAST:event_jTableOperacionesKeyPressed

    private void jMenuItemCpacidadesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItemCpacidadesActionPerformed
        initCapacidades();
    }//GEN-LAST:event_jMenuItemCpacidadesActionPerformed

    private void escribirProcesos() {
        int np = jTableOperaciones.getRowCount() - 4;
        
        for(int i = 0; i < np; ++i) {
            jTableOperaciones.setValueAt("Proceso " + (i + 1), i, 0);
        }
    }
    
    private void initPronosticos(int type) {
        if(type == SUAV) {
            // Inicializar tablas
            String[] columnNames = {"Periodo", "Demanda", "At"};
            Object[][] data = {{"", "", ""}};
            
            DefaultTableModel model = new DefaultTableModel(data, columnNames);
            jTablePeriodos.setModel(model);
            
            ses = new SuavizacionExponencialSimple();
            ses.obtenerYp(jTablePronRes, jTextFieldA, jTextFieldB);
            
            // Inicalizar cuadros de texto
            jTextFieldAlpha.setText("");
            jTextFieldBeta.setText("");
            jTextFieldGamma.setText("");
            jTextFieldA.setText("");
            jTextFieldB.setText("");
            // Bloquear
            jTextFieldBeta.setEnabled(false);
            jTextFieldGamma.setEnabled(false);
            jComboBoxM.setEnabled(false);
            
            optionPron = SUAV;
        } else if(type == WINM) {
            String[] columnNames = {"Periodo", "Demanda", "Ft", "Tt", "It"};
            Object[][] data = {{"", "", "", "", ""}};
            
            DefaultTableModel model = new DefaultTableModel(data, columnNames);
            jTablePeriodos.setModel(model);
            
            wmlt = new WinterMultiplicativo();
            wmlt.obtenerYp(jTablePronRes, jTextFieldA, jTextFieldB);
            
            // Inicalizar cuadros de texto
            jTextFieldAlpha.setText("");
            jTextFieldBeta.setText("");
            jTextFieldGamma.setText("");
            jTextFieldA.setText("");
            jTextFieldB.setText("");
            // Bloquear
            jTextFieldBeta.setEnabled(true);
            jTextFieldGamma.setEnabled(true);
            jComboBoxM.setEnabled(false);
            
            optionPron = WINM;
        } else if(type == WINC) {
            String[] columnNames = {"Periodo", "Demanda", "Demanda anterior"};
            Object[][] data = {{"", "", ""}};
            
            DefaultTableModel model = new DefaultTableModel(data, columnNames);
            jTablePeriodos.setModel(model);
            
            wcom = new WinterCompleto();
            wcom.obtenerYp(jTablePronRes, jTextFieldA, jTextFieldB);
            
            // Inicalizar cuadros de texto
            jTextFieldAlpha.setText("");
            jTextFieldBeta.setText("");
            jTextFieldGamma.setText("");
            jTextFieldA.setText("");
            jTextFieldB.setText("");
            // Bloquear
            jTextFieldBeta.setEnabled(true);
            jTextFieldGamma.setEnabled(true);
            jComboBoxM.setEnabled(true);
            
            optionPron = WINC;
        }
    }
    
    private void calcularSuavizacionExponencialSimple() {
        int n = jTablePeriodos.getRowCount();
        
        if(n > 0){
            ses = new SuavizacionExponencialSimple();
            double demand, alpha;

            for(int i = 0;i < n; ++i) {
                try {
                    demand = Double.parseDouble(jTablePeriodos.getValueAt(i, 1).toString());
                    if(!ses.isValidDemand(demand)) demand = 0.0;
                } catch(NumberFormatException e) {
                    demand = 0.0;
                }
                
                jTablePeriodos.setValueAt(demand, i, 1);
                ses.addPeriodo(jTablePeriodos.getValueAt(i, 0).toString(), demand, 0);
            }

            try {
                alpha = Double.parseDouble(jTextFieldAlpha.getText());
                if(!ses.isValidConstant(alpha)) alpha = 0.0;
            } catch(NumberFormatException e) {
                alpha = 0.0;
            }
            
            jTextFieldAlpha.setText(String.valueOf(alpha));
            
            ses.addAlpha(alpha);
            jTextFieldAlpha.setText(ses.obtenerAlpha());
            ses.calcular(Integer.parseInt(jSpinnerPeriodos.getValue().toString()));
            ses.obtenerAt(jTablePeriodos);
            ses.obtenerYp(jTablePronRes, jTextFieldA, jTextFieldB);
            mostrarErrores(ses);
        }
    }
    
    private void calcularWinterMultiplicativo() {
        int n = jTablePeriodos.getRowCount();
        
        if(n > 0){
            wmlt = new WinterMultiplicativo();
            double demand, alpha, beta, gamma;

            for(int i = 0;i < n; ++i) {
                try {
                    demand = Double.parseDouble(jTablePeriodos.getValueAt(i, 1).toString());
                    if(!wmlt.isValidDemand(demand)) demand = 0.0;
                } catch(NumberFormatException e) {
                    demand = 0.0;
                }
                
                jTablePeriodos.setValueAt(demand, i, 1);
                wmlt.addPeriodo(jTablePeriodos.getValueAt(i, 0).toString(), demand, 0, 0, 0);
            }

            try {
                alpha = Double.parseDouble(jTextFieldAlpha.getText());
                if(!wmlt.isValidConstant(alpha)) alpha = 0.0;
            } catch(NumberFormatException e) {
                alpha = 0.0;
            }
            
            try {
                beta = Double.parseDouble(jTextFieldBeta.getText());
                if(!wmlt.isValidConstant(beta)) beta = 0.0;
            } catch(NumberFormatException e) {
                beta = 0.0;
            }
            
            try {
                gamma = Double.parseDouble(jTextFieldGamma.getText());
                if(!wmlt.isValidConstant(gamma)) gamma = 0.0;
            } catch(NumberFormatException e) {
                gamma = 0.0;
            }
            
            jTextFieldAlpha.setText(String.valueOf(alpha));
            jTextFieldBeta.setText(String.valueOf(beta));
            jTextFieldGamma.setText(String.valueOf(gamma));
            
            wmlt.addAlpha(alpha);
            wmlt.addBeta(beta);
            wmlt.addGamma(gamma);
            wmlt.calcular(Integer.parseInt(jSpinnerPeriodos.getValue().toString()));
            wmlt.obtenerFTI(jTablePeriodos);
            wmlt.obtenerYp(jTablePronRes, jTextFieldA, jTextFieldB);
            mostrarErrores(wmlt);
        }
    }
    
    private void calcularWinterCompleto() {
        int n = jTablePeriodos.getRowCount();
        
        if(n > 0){
            wcom = new WinterCompleto();
            double demand, demandAnt, alpha, beta, gamma, m;

            for(int i = 0;i < n; ++i) {
                try {
                    demand = Double.parseDouble(jTablePeriodos.getValueAt(i, 1).toString());
                    if(!wcom.isValidDemand(demand)) demand = 0.0;
                } catch(NumberFormatException e) {
                    demand = 0.0;
                }
                
                try {
                    demandAnt = Double.parseDouble(jTablePeriodos.getValueAt(i, 2).toString());
                    if(!wcom.isValidDemand(demandAnt)) demandAnt = 0.0;
                } catch(NumberFormatException e) {
                    demandAnt = 0.0;
                }
                
                jTablePeriodos.setValueAt(demand, i, 1);
                jTablePeriodos.setValueAt(demandAnt, i, 2);
                wcom.addPeriodo(jTablePeriodos.getValueAt(i, 0).toString(), demand, demandAnt);
            }

            try {
                alpha = Double.parseDouble(jTextFieldAlpha.getText());
                if(!wcom.isValidConstant(alpha)) alpha = 0.0;
            } catch(NumberFormatException e) {
                alpha = 0.0;
            }
            
            try {
                beta = Double.parseDouble(jTextFieldBeta.getText());
                if(!wcom.isValidConstant(beta)) beta = 0.0;
            } catch(NumberFormatException e) {
                beta = 0.0;
            }
            
            try {
                gamma = Double.parseDouble(jTextFieldGamma.getText());
                if(!wcom.isValidConstant(gamma)) gamma = 0.0;
            } catch(NumberFormatException e) {
                gamma = 0.0;
            }
            
            int idx = jComboBoxM.getSelectedIndex();
            
            if(idx == 0) m = 345;
            else if(idx == 1) m = 52;
            else if(idx == 2) m = 12;
            else m = 4;
            
            jTextFieldAlpha.setText(String.valueOf(alpha));
            jTextFieldBeta.setText(String.valueOf(beta));
            jTextFieldGamma.setText(String.valueOf(gamma));
            
            wcom.addAlpha(alpha);
            wcom.addBeta(beta);
            wcom.addGamma(gamma);
            wcom.addUt(m);
            wcom.calcular(Integer.parseInt(jSpinnerPeriodos.getValue().toString()));
            wcom.obtenerYp(jTablePronRes, jTextFieldA, jTextFieldB);
            mostrarErrores(wcom);
        }
    }
    
    private void mostrarErrores(MetodosPronosticos mp) {
        jTextFieldDAM.setText(mp.obtenerDam());
        jTextFieldER.setText(mp.obtenerEr());
        jTextFieldERM.setText(mp.obtenerEmc());
        jTextFieldPEM.setText(mp.obtenerPem() + " %");
        jTextFieldPEMA.setText(mp.obtenerPema() + " %");
    }
    
    private void initTableOperacion() {
        numProd = (int) jSpinnerProductos.getValue();
        // Inicializar tablas
        String[] columnNames = new String[9 + numProd];
        
        columnNames[0] = "Operaciones";
        for(int i = 1; i <= numProd; ++i) columnNames[i] = "Producto" + i;
        columnNames[numProd + 1] = "Máquinas disponibles por proceso";
        columnNames[numProd + 2] = "Días hábiles en que se programan las máquinas";
        columnNames[numProd + 3] = "Número de trabajadores por máquina";
        columnNames[numProd + 4] = "Número de trabajadores Disponibles";
        columnNames[numProd + 5] = "Horas de mantenimiento por máquina";
        columnNames[numProd + 6] = "Rendimiento del trabajo INRs";
        columnNames[numProd + 7] = "Pérdidas operacionales";
        columnNames[numProd + 8] = "Factor de utilización de la maquinaria(%)";
        
        Object[][] data = new Object[5][9 + numProd];
        for(int i = 0;i < numProd + 9; ++i) {
            data[0][i] = "";
            data[1][i] = "";
            data[2][i] = "";
            data[3][i] = "";
            data[4][i] = "";
        }
        data[0][0] = "Proceso 1";
        data[1][0] = "Demanda inicial";
        data[2][0] = "Inventario Inicial";
        data[3][0] = "Tiempo de preparación en horas";
        data[4][0] = "Tamaño de cada lote";
        
        DefaultTableModel model = new DefaultTableModel(data, columnNames);
        jTableOperaciones.setModel(model);
    }
    
    private void initCapacidades() {
        jSpinnerProductos.setValue(1);
        initTableOperacion();
        
        jSpinnerProductos.setEnabled(true);
        jSpinnerNumTurnos.setEnabled(true);
        jSpinnerHoras.setEnabled(true);
        jSpinnerMinutos.setEnabled(true);
        jComboBoxHorizontePlaneacion.setEnabled(true);
        jTextIncapacidadLaboral.setEnabled(true);
        jTextFieldActividadesLudicas.setEnabled(true);
        jTextFieldParadasPlanta.setEnabled(true);
        jButtonCalcularCapacidades.setEnabled(true);
    }
    
    public void calcularCapacidades() {
        mcap = new MetodosCapacidades();
        int sz = jTableOperaciones.getRowCount() - 4;
        int np = Integer.parseInt(jSpinnerProductos.getValue().toString());
        String name;
        ArrayList<Double> prods = new ArrayList<Double>();
        double data;
        double vals[] = new double[8];
        
        // Leer datos operaciones
        for(int i = 0;i < sz; ++i) {
            name = jTableOperaciones.getValueAt(i, 0).toString();
            
            prods.clear();
            for(int j = 1;j <= np; ++j) {
                try {
                    data = Double.parseDouble(jTableOperaciones.getValueAt(i, j).toString());
                    if(data < 0.0) data = 0.0;
                } catch(NumberFormatException e) {
                    data = 0.0;
                }
                prods.add(data);
                jTableOperaciones.setValueAt(data, i, j);
            }
            
            for(int j = 0; j < 8; ++j) {
                try {
                    vals[j] = Double.parseDouble(jTableOperaciones.getValueAt(i, j + np + 1).toString());
                } catch(NumberFormatException e) {
                    vals[j] = 0.0;
                }
                jTableOperaciones.setValueAt(vals[j], i, j + np + 1);
            }
            
            mcap.addOperacion(name, prods, vals[0], vals[1], vals[2], vals[3], vals[4], vals[5], vals[6], vals[7]);
        }
        
        // Leer Demanda inicial, Inventario inicial, Tiempo de preparación en horas y Tamaño de cada lote
        for(int i = 0;i < np; ++i) {
            try {
                data = Double.parseDouble(jTableOperaciones.getValueAt(sz, i + 1).toString());
                if(data < 0.0) data = 0.0;
            } catch(NumberFormatException e) {
                data = 0.0;
            }
            jTableOperaciones.setValueAt(data, sz, i + 1);
            mcap.addDemandaInicial(data);
            
            try {
                data = Double.parseDouble(jTableOperaciones.getValueAt(sz + 1, i + 1).toString());
                if(data < 0.0) data = 0.0;
            } catch(NumberFormatException e) {
                data = 0.0;
            }
            jTableOperaciones.setValueAt(data, sz + 1, i + 1);
            mcap.addInventarioInicial(data);
            
            try {
                data = Double.parseDouble(jTableOperaciones.getValueAt(sz + 2, i + 1).toString());
                if(data < 0.0) data = 0.0;
            } catch(NumberFormatException e) {
                data = 0.0;
            }
            jTableOperaciones.setValueAt(data, sz + 2, i + 1);
            mcap.addTiempoPreparacion(data);
            
            try {
                data = Double.parseDouble(jTableOperaciones.getValueAt(sz + 3, i + 1).toString());
                if(data < 0.0) data = 0.0;
            } catch(NumberFormatException e) {
                data = 0.0;
            }
            jTableOperaciones.setValueAt(data, sz + 3, i + 1);
            mcap.addTamLote(data);
        }
        
        // Lectura demás datos capacidades
        double numTurnos = Double.parseDouble(jSpinnerNumTurnos.getValue().toString());
        mcap.addNumTurnos(numTurnos);
        
        double horas = Double.parseDouble(jSpinnerHoras.getValue().toString());
        double minutos = Double.parseDouble(jSpinnerMinutos.getValue().toString());
        mcap.addDuracionTurnos(horas, minutos);
        
        int idx = jComboBoxHorizontePlaneacion.getSelectedIndex();
        
        if(idx == 0) data = 1.0;
        else if(idx == 1) data = 2.0;
        else if(idx == 2) data = 3.0;
        else if(idx == 3) data = 6.0;
        else if(idx == 4) data = 12.0;
        else data = 24.0;
        
        mcap.addHorizontePlaneacion(data);
        
        try {
            data = Double.parseDouble(jTextIncapacidadLaboral.getText());
            if(data < 0.0) data = 0.0;
        } catch(NumberFormatException e) {
            data = 0.0;
        }
        jTextIncapacidadLaboral.setText(String.valueOf(data));
        mcap.addIncapacidadLaboral(data);
        
        try {
            data = Double.parseDouble(jTextFieldActividadesLudicas.getText());
            if(data < 0.0) data = 0.0;
        } catch(NumberFormatException e) {
            data = 0.0;
        }
        jTextFieldActividadesLudicas.setText(String.valueOf(data));
        mcap.addActividadesLudicasCulturales(data);
        
        try {
            data = Double.parseDouble(jTextFieldParadasPlanta.getText());
            if(data < 0.0) data = 0.0;
        } catch(NumberFormatException e) {
            data = 0.0;
        }
        jTextFieldParadasPlanta.setText(String.valueOf(data));
        mcap.addParadasPlanta(data);
        
        String columnNames[] = {"Operación", "M. disp", "M. prog", "M. ociosas", "T. disp", "T. prog", "T. ociosas"};
        Object[][] tableData = new Object[sz][7];
        DefaultTableModel model = new DefaultTableModel(tableData, columnNames);
        jTableOpeRes.setModel(model);
        
        mcap.calcular(jTableOpeRes);
        
        ArrayList<Double> caps = mcap.obtenerCapacidades();
        jTextFieldCt.setText(mcap.aproxDouble(caps.get(0)));
        jTextFieldCds.setText(mcap.aproxDouble(caps.get(1)));
        jTextFieldCr.setText(mcap.aproxDouble(caps.get(2)));
        jTextFieldCi.setText(mcap.aproxDouble(caps.get(3)));
        jTextFieldFus.setText(mcap.aproxDouble(caps.get(4)) + "%");
        jTextFieldFuci.setText(mcap.aproxDouble(caps.get(5)) + "%");
    }
    
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(Principal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(Principal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(Principal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Principal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Principal().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JMenuBar barraMenus;
    private javax.swing.JButton buttonNuevo;
    private javax.swing.JButton jButtonCalcularCapacidades;
    private javax.swing.JButton jButtonCalcularPron;
    private javax.swing.JButton jButtonCalcularPron1;
    private javax.swing.JButton jButtonGrafica;
    private javax.swing.JComboBox jComboBoxHorizontePlaneacion;
    private javax.swing.JComboBox jComboBoxM;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel17;
    private javax.swing.JLabel jLabel18;
    private javax.swing.JLabel jLabel19;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel20;
    private javax.swing.JLabel jLabel21;
    private javax.swing.JLabel jLabel22;
    private javax.swing.JLabel jLabel23;
    private javax.swing.JLabel jLabel24;
    private javax.swing.JLabel jLabel25;
    private javax.swing.JLabel jLabel27;
    private javax.swing.JLabel jLabel28;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JMenu jMenu2;
    private javax.swing.JMenuItem jMenuItemCpacidades;
    private javax.swing.JMenuItem jMenuItemSuavizacion;
    private javax.swing.JMenuItem jMenuItemWinterC;
    private javax.swing.JMenuItem jMenuItemWinterM;
    private javax.swing.JMenu jMenuPronostico;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel6;
    private javax.swing.JPanel jPanel7;
    private javax.swing.JPanel jPanelPronData;
    private javax.swing.JPanel jPanelPronData1;
    private javax.swing.JPanel jPanelPronData3;
    private javax.swing.JPanel jPanelPronosticos;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JScrollPane jScrollPane4;
    private javax.swing.JScrollPane jScrollPane5;
    private javax.swing.JScrollPane jScrollPane6;
    private javax.swing.JPopupMenu.Separator jSeparator1;
    private javax.swing.JSpinner jSpinnerHoras;
    private javax.swing.JSpinner jSpinnerMinutos;
    private javax.swing.JSpinner jSpinnerNumTurnos;
    private javax.swing.JSpinner jSpinnerPeriodos;
    private javax.swing.JSpinner jSpinnerProductos;
    private javax.swing.JTabbedPane jTabbedOperaciones;
    private javax.swing.JTable jTableOpeRes;
    private javax.swing.JTable jTableOperaciones;
    private javax.swing.JTable jTablePeriodos;
    private javax.swing.JTable jTablePeriodos3;
    private javax.swing.JTable jTablePeriodosCon;
    private javax.swing.JTable jTablePronRes;
    private javax.swing.JTextField jTextFieldA;
    private javax.swing.JTextField jTextFieldActividadesLudicas;
    private javax.swing.JTextField jTextFieldAlpha;
    private javax.swing.JTextField jTextFieldB;
    private javax.swing.JTextField jTextFieldBeta;
    private javax.swing.JTextField jTextFieldCds;
    private javax.swing.JTextField jTextFieldCi;
    private javax.swing.JTextField jTextFieldCr;
    private javax.swing.JTextField jTextFieldCt;
    private javax.swing.JTextField jTextFieldDAM;
    private javax.swing.JTextField jTextFieldER;
    private javax.swing.JTextField jTextFieldERM;
    private javax.swing.JTextField jTextFieldFuci;
    private javax.swing.JTextField jTextFieldFus;
    private javax.swing.JTextField jTextFieldGamma;
    private javax.swing.JTextField jTextFieldPEM;
    private javax.swing.JTextField jTextFieldPEMA;
    private javax.swing.JTextField jTextFieldParadasPlanta;
    private javax.swing.JTextField jTextIncapacidadLaboral;
    private javax.swing.JToolBar jToolBar2;
    private javax.swing.JMenu menuArchivo;
    private javax.swing.JMenu menuItemNuevo;
    private javax.swing.JMenuItem menuItemSalir;
    private javax.swing.JPanel panelAreaTrabajo;
    // End of variables declaration//GEN-END:variables

   

}
